package homework;

import java.util.Arrays;

public class Sum {

    private int[][] arr;

    public Sum(int[][] arr) {
        this.arr = arr;
    }


    // 行求和 列求和
    public void SumHang(){
        int[] sumhang = new int[arr.length];
        int[] sumLie= new int[arr.length];
        for (int i = 0; i < this.arr.length; i++) {
            int sumh =0 ;
            int suml=0;
            for (int j = 0; j <this.arr.length ; j++) {
                sumh+=arr[i][j];
                suml+=arr[j][i];

            }
            sumhang[i]=sumh;
            sumLie[i]=suml;
        }
        System.out.println("行求和："+Arrays.toString(sumhang));
        System.out.println("列求和: "+Arrays.toString(sumLie));
    }


    public void Duijiaoxian(){
        // \ 对角线
        int sumLeft =0;
        // / 对角线
        int sumRight =0;

        for (int i = 0; i < this.arr.length; i++) {
            sumLeft +=arr[i][i];
            sumRight+=arr[i][this.arr.length-i-1];
        }
        System.out.println("\\ 对角线: "+sumLeft);
        System.out.println("/ 对角线: "+sumRight);
    }


}
